﻿//---------------------------------------------------------------------------

#ifndef Main_FormH
#define Main_FormH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Grids.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include "I2CDriver.h"
#include <Dialogs.hpp>
#include <OleServer.hpp>
#include <Menus.hpp>
#include <jpeg.hpp>
#include <pngimage.hpp>
#include <ADODB.hpp>
#include <DB.hpp>
#include "AboutBox_Form.h"
#include <InvokeRegistry.hpp>
#include <Rio.hpp>
#include <SOAPHTTPClient.hpp>
#include <memory>
#include "ServiceSaveFile.h"
#define USE_24C64 1
#define USE_24C02 0

#define CLR_BLACK_BOX 0
#define RELEASE 1

#define Repeat_Count 5

typedef union
{
	struct
	{
		BYTE tSN[20];
		BYTE tDate[10];
		BYTE tTime[8];
		BYTE RESERD[12];
	};
	BYTE tRcd[50];
} TEST_RECORD;

//---------------------------------------------------------------------------
bool __fastcall VerifyFunc();
void __fastcall Write_FruData();
void __fastcall Read_FruData();
int __fastcall ScanBarCode(char rw);
void __fastcall CheckSumFunc(void);
void __fastcall CheckTimeFunc(void);
void __fastcall Save_HEXData(AnsiString RW);
void __fastcall Save_TXTData(AnsiString RW,String msg);
void __fastcall Save_BINData(AnsiString RW);
bool __fastcall Save_Check_SN();
void __fastcall Open_Ini_File(AnsiString FileName);
void __fastcall Save_Ini_File(AnsiString FileName);
void __fastcall Initial_USB_Intreface();
void __fastcall Initial_ISA_Intreface();
void __fastcall Date_Calc(String str);
bool __fastcall ClrBBox(void);
bool __fastcall CheckEEPAfterClr();
bool __fastcall CheckEEPBeforClr();
TEST_RECORD __fastcall FormatRcdUnion(String sn);
int __fastcall StreamAddUnion(TEST_RECORD Rcd, String FileName);
String RcdToString(TEST_RECORD Rcd);
void __fastcall TransferStreamToCsv(String StreamFile, String CsvFile);
void __fastcall SaveSnInforToCsv(String s, String RW);
bool __fastcall LockFunctionTest();
String __fastcall GetUploadFileName(String SN, bool bResult);
void __fastcall FileUpload();
void __fastcall LogStoreTask(String FileName, String SourcePath);
bool __fastcall CUploadLogService(String FileName, String SourcePath);
String __fastcall GetFileHeader(String SN, String sResult, String Path);
String __fastcall GetHostInfo();
String RcdToString(TEST_RECORD Rcd);
bool __fastcall EnterTOFunc();
bool __fastcall ExitTOFunc();
void __fastcall WriteTOFunc();
bool __fastcall VerifyFunc();
String __fastcall GetDateCompiled();

bool __fastcall Cali_WriteEep(BYTE salve, int add, BYTE Value);
BYTE __fastcall Cali_ReadEep(BYTE add, WORD ptr);
bool __fastcall Read2B(String& log);

class TMainForm : public TForm
{
	__published : // IDE-managed Components
				  TStringGrid *Source_StringGrid;
	TStringGrid *Reading_StringGrid;
	TButton *Write_Verify;
	TImage *Image1;
	TProgressBar *ProgressBar1;
	TStatusBar *StatusBar;
	TEdit *Start_Time_Edit;
	TEdit *End_Time_Edit;
	TLabel *Label5;
	TLabel *Label6;
	TLabel *Status_Label;
	TLabel *Label2;
	TLabel *Rev_Label;
	TButton *Read_Verify;
	TLabel *Label3;
	TLabel *Barcode_Label;
	TLabel *Model_Name_Label0;
	TLabel *Model_Name_Label1;
	TLabel *Label8;
	TLabel *TXT_Label;
	TLabel *Hex_Label;
	TMainMenu *MainMenu1;
	TMenuItem *File;
	TMenuItem *Rev;
	TMenuItem *WriteVerify;
	TMenuItem *ReadVerify;
	TMenuItem *Exit;
	TMenuItem *AddressSetting;
	TMenuItem *I2CInterface;
	TMenuItem *ISA;
	TMenuItem *USB;
	TMenuItem *USBI2C_Freq;
	TMenuItem *LinkI2CInterface;
	TMenuItem *SaveTestData;
	TMenuItem *TXT_Data;
	TMenuItem *None_TXT;
	TMenuItem *PASS_TXT;
	TMenuItem *FAIL_TXT;
	TMenuItem *All_TXT;
	TMenuItem *Hex_Data;
	TMenuItem *None_HEX;
	TMenuItem *PASS_HEX;
	TMenuItem *FAIL_HEX;
	TMenuItem *All_HEX;
	TMenuItem *SNDuplicateWarning;
	TLabel *FuncLabel;
	TLabel *SN_Dup_Label;
	TLabel *Model_No_Label;
	TLabel *Label4;
	TMenuItem *BIN_Data;
	TMenuItem *None_BIN;
	TMenuItem *PASS_BIN;
	TMenuItem *FAIL_BIN;
	TMenuItem *All_BIN;
	TLabel *BIN_Label;
	TButton *Exit_Button;
	TMemo *memo;
	TADOQuery *ADOQuery1;
	TMenuItem *MES1;
	TMenuItem *Edit1;
	TMenuItem *ckiMesOffLine;
	TMenuItem *Unlock;
	TMenuItem *Other1;
	TMenuItem *AutoExit1;
	TMenuItem *NI8451;
	TADOStoredProc *sp1;
	TMenuItem *mniOpenDir;
	TMenuItem *mniUploadLog;
	THTTPRIO *htpr1;
	TMenuItem *mniGetBom2;
	void __fastcall FormCreate(TObject *Sender);
	void __fastcall Write_VerifyClick(TObject *Sender);
	void __fastcall Exit_ButtonClick(TObject *Sender);
	void __fastcall FormDestroy(TObject *Sender);
	void __fastcall Reading_StringGridDrawCell(TObject *Sender,
											   int ACol, int ARow, TRect &Rect, TGridDrawState State);
	void __fastcall Reading_StringGridClick(TObject *Sender);
	void __fastcall Source_StringGridClick(TObject *Sender);
	void __fastcall Read_VerifyClick(TObject *Sender);
	void __fastcall About1Click(TObject *Sender);
	void __fastcall ISAClick(TObject *Sender);
	void __fastcall USBClick(TObject *Sender);
	void __fastcall NI8451Click(TObject *Sender);
	void __fastcall USBI2C_FreqClick(TObject *Sender);
	void __fastcall LinkI2CInterfaceClick(TObject *Sender);
	void __fastcall ExitClick(TObject *Sender);
	void __fastcall None_TXTClick(TObject *Sender);
	void __fastcall All_TXTClick(TObject *Sender);
	void __fastcall PASS_TXTClick(TObject *Sender);
	void __fastcall FAIL_TXTClick(TObject *Sender);
	void __fastcall RevClick(TObject *Sender);
	void __fastcall AddressSettingClick(TObject *Sender);
	void __fastcall None_HEXClick(TObject *Sender);
	void __fastcall All_HEXClick(TObject *Sender);
	void __fastcall PASS_HEXClick(TObject *Sender);
	void __fastcall FAIL_HEXClick(TObject *Sender);
	void __fastcall SNDuplicateWarningClick(TObject *Sender);
	void __fastcall WriteVerifyClick(TObject *Sender);
	void __fastcall ReadVerifyClick(TObject *Sender);
	void __fastcall None_BINClick(TObject *Sender);
	void __fastcall PASS_BINClick(TObject *Sender);
	void __fastcall FAIL_BINClick(TObject *Sender);
	void __fastcall All_BINClick(TObject *Sender);
	void __fastcall Button3Click(TObject *Sender);
	void __fastcall Edit1Click(TObject *Sender);
	void __fastcall ckiMesOffLineClick(TObject *Sender);
	void __fastcall UnlockClick(TObject *Sender);

	void __fastcall mniAboutClick(TObject *Sender);
	String __fastcall Get99ModelNumber(String SN);
    String __fastcall Get99ModelNumber2(String SN);
    String __fastcall Get91From99(String Bom99);
    String __fastcall Get99From91(String Bom91);
	bool __fastcall IsPacked(String SN);
	void __fastcall mniOpenDirClick(TObject *Sender);
private: // User declarations
public:	 // User declarations
	__fastcall TMainForm(TComponent *Owner);
	_di_ServiceSaveFileSoap ServiceSaveFile;
	_di_ServiceSaveFileSoap GetServiceSaveFileSoap();
	__property
		_di_ServiceSaveFileSoap SaveFileService = {read = GetServiceSaveFileSoap};
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
extern String Com_port;

//---------------------------------------------------------------------------
#endif
